<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="text" indent="no"  />
	
		<xsl:template match="/">
&lt;cfcomponent displayname="<xsl:value-of select="//bean/@name"/>" output="false"&gt;
		<xsl:for-each select="root/bean/dbtable/column">&lt;cfproperty name="<xsl:value-of select="@name" />" type="<xsl:value-of select="@type" />" default="" /&gt;
		</xsl:for-each>
	&lt;!---
	PROPERTIES
	---&gt;
	&lt;cfset variables.hashmap = createObject("java", "java.util.HashMap").init() /&gt;

	&lt;!---
	INITIALIZATION / CONFIGURATION
	---&gt;
	&lt;cffunction name="init" access="public" returntype="<xsl:value-of select="//bean/@path"/>" output="false"&gt;
		&lt;cfargument name="inHashmap" type="struct" required="false" default="" /&gt;
		&lt;cfscript&gt;
			var x = 0;
			var hmPropertyNames = structKeyList(arguments.inHashmap);
			var requiredPropertyNames = "<xsl:for-each select="root/bean/dbtable/column"><xsl:value-of select="@name" />,</xsl:for-each>id";
			var propertyNames = "<xsl:for-each select="root/bean/dbtable/column"><xsl:value-of select="@name" />,</xsl:for-each>id";
			var propertyName = "";
			var propertyValue = "";
			var func = "";
		  for(x = 1; x lte listLen(propertyNames); x = x+1) {
		  	propertyName = listGetAt(propertyNames,x);
		  	if(listFindNoCase(hmPropertyNames,propertyName) AND (isStruct(inHashmap[propertyName]) OR toString(inHashmap[propertyName]) gt "")) {
		  		func = this["set"&amp;propertyName];
		  		func(inHashmap[propertyName]);
		  	}		  	
		  }
		&lt;/cfscript&gt;

		&lt;cfreturn this /&gt;
 	&lt;/cffunction&gt;

	&lt;!---
	ACCESSORS
	---&gt;
	&lt;cffunction name="getHashmap" access="public" returntype="any" output="false"&gt;
		&lt;cfreturn variables.hashmap /&gt;
 	&lt;/cffunction&gt;

	<xsl:for-each select="root/bean/dbtable/column">
	&lt;cffunction name="set<xsl:value-of select="@name" />" access="public" returntype="void" output="false"&gt;
		&lt;cfargument name="<xsl:value-of select="@name" />" type="<xsl:value-of select="@type" />" required="true" /&gt;
		&lt;cfscript&gt;
		<xsl:choose>
		<xsl:when test="@type='date'">
		var daDate = createObject("java","java.util.Date").init(createOdbcDateTime(arguments.<xsl:value-of select="@name" />).getTime());
		variables.hashmap.put("<xsl:value-of select="@name" />",daDate);
		</xsl:when>
		<xsl:when test="@type='numeric'">
		var daInt = createObject("java","java.lang.Integer").init(arguments.<xsl:value-of select="@name" />);
		variables.hashmap.put("<xsl:value-of select="@name" />",daInt);
		</xsl:when>
		<xsl:otherwise>
		variables.hashmap.put("<xsl:value-of select="@name" />",arguments.<xsl:value-of select="@name" />);
		</xsl:otherwise>
		</xsl:choose>
		&lt;/cfscript&gt;
	&lt;/cffunction&gt;
	&lt;cffunction name="get<xsl:value-of select="@name" />" access="public" returntype="<xsl:value-of select="@type" />" output="false"&gt;
		&lt;cfreturn variables.hashmap.get("<xsl:value-of select="@name" />") /&gt;
	&lt;/cffunction&gt;
</xsl:for-each>

	&lt;!---
	PUBLIC FUNCTIONS
	---&gt;
	<!-- custom code -->

&lt;/cfcomponent&gt;</xsl:template>
</xsl:stylesheet>